﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MoneyManagerNET
{
   public class Factory
    {
       public Dictionary<Type, Type> registered=new Dictionary<Type,Type>();

       public T CreateNew<T>() {
           Type t=typeof(T); 
           Type r=null;
           if (registered.TryGetValue(t,out r)) {
               var c = (T)Activator.CreateInstance(r);
               return c;
           }
           else
               return default(T);
       }

       public static Factory Instance;

       public static T New<T>() {
           if (Instance == null)
               return default(T);
           else
               return Instance.CreateNew<T>();
       }
    }
}
